<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师/学生登录系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a2980, #26d0ce);
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            color: #333;
            overflow-x: hidden;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 50px rgba(0, 0, 0, 0.25);
            width: 100%;
            max-width: 500px;
            padding: 50px;
            position: relative;
            overflow: hidden;
            transition: all 0.4s ease;
            transform: translateY(0);
        }

        .login-container:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
        }

        .login-header {
            text-align: center;
            margin-bottom: 40px;
            position: relative;
            z-index: 2;
        }

        .system-logo {
            width: 100px;
            height: 100px;
            background: linear-gradient(135deg, #4776E6, #8E54E9);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            box-shadow: 0 10px 20px rgba(142, 84, 233, 0.3);
        }

        .system-logo i {
            font-size: 50px;
            color: white;
        }

        .login-header h2 {
            color: #2c3e50;
            margin: 0;
            font-size: 36px;
            font-weight: 800;
            letter-spacing: 0.5px;
            background: linear-gradient(135deg, #4776E6, #8E54E9);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }

        .login-header p {
            color: #7f8c8d;
            margin: 15px 0 0;
            font-size: 18px;
        }

        .role-select {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
        }

        .role-option {
            flex: 1;
            text-align: center;
            padding: 20px 15px;
            border: 2px solid #e0e7ff;
            border-radius: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
            background: #f8f9ff;
            position: relative;
            overflow: hidden;
        }

        .role-option.active {
            border-color: #5b67ca;
            background: #eef2ff;
            box-shadow: 0 10px 25px rgba(91, 103, 202, 0.15);
            transform: translateY(-5px);
        }

        .role-option.active:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: linear-gradient(90deg, #4776E6, #8E54E9);
        }

        .role-option i {
            font-size: 36px;
            margin-bottom: 12px;
            color: #7f8c8d;
            transition: all 0.3s ease;
        }

        .role-option.active i {
            color: #5b67ca;
            transform: scale(1.1);
        }

        .role-option div {
            font-size: 18px;
            font-weight: 600;
            color: #5b67ca;
        }

        .form-group {
            margin-bottom: 30px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 12px;
            color: #2c3e50;
            font-size: 16px;
            font-weight: 600;
        }

        .input-container {
            position: relative;
        }

        .form-control {
            width: 100%;
            padding: 18px 20px 18px 55px;
            border: 2px solid #e0e7ff;
            border-radius: 12px;
            font-size: 16px;
            color: #2c3e50;
            transition: all 0.3s ease;
            background: #f8f9ff;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }

        .form-control:focus {
            outline: none;
            border-color: #5b67ca;
            background: #fff;
            box-shadow: 0 0 0 4px rgba(91, 103, 202, 0.2);
        }

        .input-icon {
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            color: #a0aec0;
            font-size: 20px;
            transition: all 0.3s ease;
        }

        .form-control:focus + .input-icon {
            color: #5b67ca;
        }

        .toggle-password {
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            color: #a0aec0;
            font-size: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .toggle-password:hover {
            color: #5b67ca;
        }

        .btn-login {
            width: 100%;
            padding: 18px 0;
            background: linear-gradient(135deg, #4776E6, #8E54E9);
            border: none;
            border-radius: 12px;
            color: white;
            font-size: 18px;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 10px 20px rgba(142, 84, 233, 0.3);
            position: relative;
            overflow: hidden;
        }

        .btn-login:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 30px rgba(142, 84, 233, 0.4);
        }

        .btn-login:active {
            transform: translateY(1px);
        }

        .btn-login .spinner {
            display: none;
            margin-right: 10px;
        }

        .error-message {
            color: #e53e3e;
            font-size: 16px;
            margin-top: 20px;
            text-align: center;
            padding: 15px;
            border-radius: 10px;
            background: #fff5f5;
            border: 1px solid #fed7d7;
            display: none;
        }

        .footer {
            text-align: center;
            margin-top: 30px;
            color: #718096;
            font-size: 15px;
        }

        .footer a {
            color: #5b67ca;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .footer a:hover {
            text-decoration: underline;
            color: #4c51bf;
        }

        .decoration {
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: linear-gradient(135deg, rgba(71, 118, 230, 0.1), rgba(142, 84, 233, 0.1));
            z-index: 1;
        }

        .decoration-1 {
            top: -80px;
            right: -80px;
            width: 300px;
            height: 300px;
        }

        .decoration-2 {
            bottom: -100px;
            left: -100px;
            width: 250px;
            height: 250px;
        }

        .shake {
            animation: shake 0.6s cubic-bezier(.36,.07,.19,.97) both;
        }

        @keyframes shake {
            0%, 100% {transform: translateX(0);}
            10%, 30%, 50%, 70%, 90% {transform: translateX(-10px);}
            20%, 40%, 60%, 80% {transform: translateX(10px);}
        }

        @media (max-width: 600px) {
            .login-container {
                padding: 30px 20px;
                margin: 20px;
            }

            .role-select {
                flex-direction: column;
                gap: 15px;
            }

            .role-option {
                padding: 15px;
            }

            .login-header h2 {
                font-size: 28px;
            }

            .form-control {
                padding: 15px 15px 15px 50px;
            }
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="decoration decoration-1"></div>
    <div class="decoration decoration-2"></div>

    <div class="login-header">
        <div class="system-logo">
            <i class="fas fa-graduation-cap"></i>
        </div>
        <h2>考试系统登录</h2>
        <p>请选择您的身份并登录系统</p>
    </div>

    <form id="loginForm" method="post" onsubmit="return validateForm();">
        <input type="hidden" id="role" name="role" value="teacher">

        <div class="role-select">
            <div class="role-option active" data-role="teacher" onclick="selectRole(this, 'teacher')">
                <i class="fas fa-chalkboard-teacher"></i>
                <div>教师登录</div>
            </div>
            <div class="role-option" data-role="student" onclick="selectRole(this, 'student')">
                <i class="fas fa-user-graduate"></i>
                <div>学生登录</div>
            </div>
        </div>

        <div class="form-group">
            <label for="username" id="username-label">教师工号</label>
            <div class="input-container">
                <input type="text" id="username" name="username" class="form-control" placeholder="请输入工号">
                <div class="input-icon">
                    <i class="fas fa-user-tie"></i>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <div class="input-container">
                <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码">
                <div class="input-icon">
                    <i class="fas fa-lock"></i>
                </div>
                <div class="toggle-password" onclick="togglePasswordVisibility()">
                    <i class="fas fa-eye"></i>
                </div>
            </div>
        </div>

        <button type="submit" id="btn-login" class="btn-login">
            <span id="btn-text">教师登录</span>
            <span class="spinner"><i class="fas fa-spinner fa-spin"></i></span>
        </button>

        <div id="error-message" class="error-message"></div>
    </form>

    <div class="footer">
        <p>© 2025 智能考试系统 | <a href="#">忘记密码?</a> | <a href="admin_login.jsp">管理员登录</a></p>
    </div>
</div>

<script>
    // 获取上下文路径
    const contextPath = '<%= request.getContextPath() %>';

    // 当前选中的角色
    let currentRole = 'teacher';

    function selectRole(element, role) {
        // 移除所有选项的active类
        document.querySelectorAll('.role-option').forEach(opt => {
            opt.classList.remove('active');
        });

        // 给当前选项添加active类
        element.classList.add('active');

        // 设置隐藏字段的值
        document.getElementById('role').value = role;
        currentRole = role;

        // 更新UI元素
        if (role === 'teacher') {
            document.getElementById('username-label').textContent = '教师工号';
            document.querySelector('.input-icon i').className = 'fas fa-user-tie';
            document.getElementById('username').placeholder = '请输入工号';
            document.getElementById('btn-text').textContent = '教师登录';
        } else {
            document.getElementById('username-label').textContent = '学生学号';
            document.querySelector('.input-icon i').className = 'fas fa-id-card';
            document.getElementById('username').placeholder = '请输入学号';
            document.getElementById('btn-text').textContent = '学生登录';
        }

        // 清除错误信息
        document.getElementById('error-message').style.display = 'none';
    }

    function validateForm() {
        const role = currentRole;
        const username = document.getElementById("username").value.trim();
        const password = document.getElementById("password").value;
        const errorMessage = document.getElementById("error-message");

        // 隐藏错误信息
        errorMessage.style.display = "none";
        document.querySelector(".login-container").classList.remove("shake");

        // 验证用户名
        if (username === "") {
            showError(role === 'teacher' ? "请输入教师工号" : "请输入学生学号");
            return false;
        }

        // 验证密码
        if (password === "") {
            showError("请输入密码");
            return false;
        }

        // 设置表单action基于角色
        const form = document.getElementById("loginForm");
        if (role === 'teacher') {
            form.action = contextPath + "/teacher/loginProcess";
        } else {
            form.action = contextPath + "/student/loginProcess";
        }

        // 显示加载状态
        document.getElementById("btn-text").style.display = "none";
        document.querySelector(".spinner").style.display = "inline-block";
        document.getElementById("btn-login").disabled = true;

        return true;
    }

    function showError(message) {
        const errorMessage = document.getElementById("error-message");
        errorMessage.textContent = message;
        errorMessage.style.display = "block";
        document.querySelector(".login-container").classList.add("shake");

        // 重置按钮状态
        resetButtonState();
    }

    function resetButtonState() {
        document.getElementById("btn-text").style.display = "inline";
        document.querySelector(".spinner").style.display = "none";
        document.getElementById("btn-login").disabled = false;
    }

    function togglePasswordVisibility() {
        const passwordField = document.getElementById("password");
        const icon = document.querySelector(".toggle-password i");

        if (passwordField.type === "password") {
            passwordField.type = "text";
            icon.classList.remove("fa-eye");
            icon.classList.add("fa-eye-slash");
        } else {
            passwordField.type = "password";
            icon.classList.remove("fa-eye-slash");
            icon.classList.add("fa-eye");
        }
    }

    // 初始化页面显示错误消息
    window.addEventListener('DOMContentLoaded', (event) => {
        <%
        String error = (String) request.getAttribute("error");
        if (error != null && !error.isEmpty()) {
        %>
        document.getElementById('error-message').textContent = '<%= error %>';
        document.getElementById('error-message').style.display = 'block';
        resetButtonState();
        <% } %>
    });
</script>
</body>
</html>